package com.arsn.myf.system.service.impl;

import com.arsn.myf.common.node.TreeNode;
import com.arsn.myf.common.util.StringUtils;
import com.arsn.myf.common.util.node.NodeTreeUtil;
import com.arsn.myf.system.entity.Dept;
import com.arsn.myf.system.mapper.DeptMapper;
import com.arsn.myf.system.service.DeptService;
import com.arsn.myf.system.vo.DeptVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 部门实现层
 * @author zhongrj
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    /**
     * 自定义查询部门分页数据
     * @param page
     * @param dept
     * @return
     */
    @Override
    public IPage<DeptVO> selectPageDeptList(Page<DeptVO> page, DeptVO dept) {
        return page.setRecords(baseMapper.selectPageDeptList(page,dept));
    }

    /**
     * 查询部门树
     * @param dept
     * @return
     */
    @Override
    public List<TreeNode> getDeptTree(DeptVO dept) {
        return NodeTreeUtil.getNodeTree(baseMapper.getDeptTree(dept));
    }

    /**
     * 部门懒加载列表
     * @param dept 部门参数实体
     * @return
     */
    @Override
    public List<DeptVO> getDeptLazyList(DeptVO dept) {
        //判断查询参数
        if (StringUtils.isBlank(dept.getDeptName()) && null==dept.getParentId()) {
            dept.setParentId(0L);
        }
        return baseMapper.getDeptLazyList(dept);
    }
}
